package leetcode;

public class LC42 {
    public static void main(String[] args) {

    }
    public boolean isValidBST(TreeNode root) {
        return isValidBST(root,Long.MAX_VALUE,Long.MIN_VALUE);
    }
    public boolean isValidBST(TreeNode root, long max, long min) {
        if (root == null) return true;
        if (root.val >= max || root.val <= min) return false;
        return isValidBST(root.left,root.val,min) && isValidBST(root.right,max,root.val);
    }
}
